﻿package
{
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	
	import com.urbansquall.display.*;
	
	public class Main extends InitializedSprite
	{
		[Embed(source='../assets/huge.jpg')]
		private static const HugeJPG : Class;
		
		private var m_massivePicture : Bitmap;
		private var m_scale : Number;
		private var m_mouseDown : Boolean = false;
		
		public function Main() : void {}
		
		override protected function init() : void
		{
			m_scale = 0.1;
			
			m_massivePicture = new HugeJPG();
			m_massivePicture.scaleX = m_scale;
			m_massivePicture.scaleY = m_scale;
			addChild( m_massivePicture );
					
			var textfield : TextField = new TextField();
			textfield.defaultTextFormat = new TextFormat( "Verdana", 9, 0xFFFFFF );
			textfield.autoSize = TextFieldAutoSize.LEFT;
			textfield.text = "Preloading has finished so lets start the game!\nWhich is not really a game.";
			textfield.mouseEnabled = false;
			addChild( textfield );
			
			this.addEventListener( Event.ENTER_FRAME, enterFrame );
			this.addEventListener( MouseEvent.MOUSE_DOWN, handleMouseDown );
			this.addEventListener( MouseEvent.MOUSE_UP, handleMouseUp );
		}
		
		private function handleMouseDown( a_event : MouseEvent ) : void
		{
			m_mouseDown = true;
		}
		
		private function handleMouseUp( a_event : MouseEvent ) : void
		{
			m_mouseDown = false;
		}
		
		private function enterFrame( a_event : Event ) : void
		{
			if( m_mouseDown )
			{
				m_scale += 0.001;
			}
			else
			{
				m_scale -= 0.003;
			}

			m_scale = Math.max( 0.1, m_scale );
			m_scale = Math.min( 1.0, m_scale );
			
			updatePicture();
		}
		
		private function updatePicture() : void
		{
			m_massivePicture.scaleX = m_scale;
			m_massivePicture.scaleY = m_scale;
			
			m_massivePicture.x = -this.stage.mouseX / this.stage.stageWidth * ( m_massivePicture.bitmapData.width * m_scale - this.stage.stageWidth );
			m_massivePicture.y = -this.stage.mouseY / this.stage.stageHeight * ( m_massivePicture.bitmapData.height * m_scale - this.stage.stageHeight );
		}
		
	}
	
}